package cn.com.zs.android.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import cn.com.zs.android.R;
import cn.com.zs.android.model.GameParams;
import cn.com.zs.android.util.VoiceSettings;

/**
 * 欢迎界面, 游戏背景、规则、鸣谢等等。
 * @author 曾帅
 */
public class WelcomeActivity extends Activity {
	
	private ImageView startgame, settings, default_background_music,
			default_system_sound, close_background_music, close_system_sound,
			help, about, more, exit;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE); 
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        
        this.init();
    }
    
	private void init() {
		// 游戏参数设置
		VoiceSettings.createObject(getSharedPreferences("fighthamster_settings", Context.MODE_PRIVATE));
    	startgame 					= (ImageView) findViewById(R.id.startgame);
    	settings 					= (ImageView) findViewById(R.id.settings);
    	default_background_music 	= (ImageView) findViewById(R.id.default_background_music);
    	default_system_sound 		= (ImageView) findViewById(R.id.default_system_sound);
    	close_background_music 		= (ImageView) findViewById(R.id.close_background_music);
    	close_system_sound 			= (ImageView) findViewById(R.id.close_system_sound);
    	help 						= (ImageView) findViewById(R.id.help);
    	about 						= (ImageView) findViewById(R.id.about);
    	more 						= (ImageView) findViewById(R.id.more);
    	exit 						= (ImageView) findViewById(R.id.exit);
    	this.gameSettings();
    	
    	startgame.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(WelcomeActivity.this, StartGameActivity.class);
				startActivity(intent);
			}
		});
    	
    	exit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
    }
	
	/**
	 * 游戏设置
	 */
	private void gameSettings() {
    	boolean background_music = VoiceSettings.fighthamster_settings.getBoolean("fighthamster_background_music", true);
    	boolean system_sound = VoiceSettings.fighthamster_settings.getBoolean("fighthamster_system_sound", true);
    	if (background_music) {
    		GameParams.isBackgroundMusic = true;
			default_background_music.setVisibility(View.VISIBLE);
			close_background_music.setVisibility(View.GONE);
    	} else {
    		GameParams.isBackgroundMusic = false;
    		close_background_music.setVisibility(View.VISIBLE);
    		default_background_music.setVisibility(View.GONE);
    	}
    	if (system_sound) {
    		GameParams.isSystemSound = true;
    		default_system_sound.setVisibility(View.VISIBLE);
    		close_system_sound.setVisibility(View.GONE);
    	} else {
    		GameParams.isSystemSound = false;
    		close_system_sound.setVisibility(View.VISIBLE);
    		default_system_sound.setVisibility(View.GONE);
    	}
    	
    	default_background_music.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				VoiceSettings.closeBackgroundMusic();
				default_background_music.setVisibility(View.GONE);
				close_background_music.setVisibility(View.VISIBLE);
			}
		});
    	close_background_music.setOnClickListener(new OnClickListener() {
    		
			@Override
			public void onClick(View v) {
				VoiceSettings.openBackgroundMusic();
				close_background_music.setVisibility(View.GONE);
				default_background_music.setVisibility(View.VISIBLE);
			}
		});
    	default_system_sound.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				VoiceSettings.closeSystemSound();
				default_system_sound.setVisibility(View.GONE);
				close_system_sound.setVisibility(View.VISIBLE);
			}
		});
    	close_system_sound.setOnClickListener(new OnClickListener() {
		
			@Override
			public void onClick(View v) {
				VoiceSettings.openSystemSound();
				close_system_sound.setVisibility(View.GONE);
				default_system_sound.setVisibility(View.VISIBLE);
			}
		});
	}

	@Override
	protected void onStart() {
		super.onStart();
		this.gameSettings();
	}
	
    
}